import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userinfo:sessionStorage.getItem('userinfo')?JSON.parse(sessionStorage.getItem('userinfo')):null
  },
  getters:{
     getUser(state){
       return state.userinfo
     }
  },
  mutations: {
    CHANGE_USER(state,payload){
        state.userinfo = payload
        if(payload){
          sessionStorage.setItem('userinfo',JSON.stringify(payload))
        }else{
          sessionStorage.removeItem('userinfo')
        }
    }
  },
  actions: {
    changeUser({commit},payload){
      console.log('行动');
      commit('CHANGE_USER',payload)
    }
  },
  modules: {
  }
})
